//
//  AnjiaCustomerBuildNameView.m
//  flutter_bmfmap
//
//  Created by Akey on 2020/11/16.
//

#import "AnjiaCustomerBuildNameView.h"
#import "UIView+Frame.h"

@interface AnjiaCustomerBuildNameView ()

/// 选中图片
@property(nonatomic, strong) UIImageView *selectImageView;
/// 选中图片箭头
@property(nonatomic, strong) UIImageView *selectArrowImageView;
///
@property(nonatomic, strong) UILabel *textName;

@end

@implementation AnjiaCustomerBuildNameView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI {
    [self addSubview:self.selectImageView];
    [self addSubview:self.selectArrowImageView];
    [self addSubview:self.textName];
}

- (void)setOptions:(BMFAnnotationViewOptions *)options {
    _options = options;
    UIImage *images = nil;
    UIImage *imageArrows = nil;
    if (options.selectedType == 1) {
        images = [UIImage imageNamed:@"maphome_map_tag_none3"];
        imageArrows = [UIImage imageNamed:@"矩形2_2"];
    } else if (options.selectedType == 2) {
        images = [UIImage imageNamed:@"maphome_map_tag_none2"];
        imageArrows = [UIImage imageNamed:@"矩形2_1"];
    } else {
        images = [UIImage imageNamed:@"maphome_map_tag_none1"];
        imageArrows = [UIImage imageNamed:@"矩形2"];
    }
    self.textName.text = options.title;
    
    UIImage *newImage = [images stretchableImageWithLeftCapWidth:images.size.width * 0.5 topCapHeight:images.size.height * 0.5];

    self.selectImageView.image = newImage;
    self.selectArrowImageView.image = imageArrows;
    self.selectArrowImageView.top = self.selectImageView.bottom-10;
    self.selectArrowImageView.width = imageArrows.size.width+5;
    self.selectArrowImageView.height = imageArrows.size.height+5;
    self.selectArrowImageView.centerX = self.selectImageView.centerX;
    
}

- (UIImageView *)selectImageView {
    if (!_selectImageView) {
        _selectImageView = [UIImageView new];
        _selectImageView.frame = CGRectMake(0, 0, self.width, self.height);
    }
    return _selectImageView;
}

- (UIImageView *)selectArrowImageView {
    if (!_selectArrowImageView) {
        _selectArrowImageView = [UIImageView new];
    }
    return _selectArrowImageView;
}

- (UILabel *)textName {
    if (!_textName) {
        _textName = [UILabel new];
        _textName.textColor = [UIColor whiteColor];
        _textName.font = [UIFont systemFontOfSize:13];
        _textName.textAlignment = NSTextAlignmentCenter;
        _textName.frame = CGRectMake(15, 4, self.width-30, self.height - 10);
    }
    return _textName;
}

@end
